package com.dev.utils.app.assist;

import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.window.dialog.ToastDialog;
import ohos.vibrator.agent.VibratorAgent;
import ohos.vibrator.bean.VibrationPattern;

import java.util.List;

/**
 * 震动效果的工具类
 */
public class
BeepVibrateAssist {

    private int[] timing = {1000, 1000, 2000, 5000};

    private int[] intensity = {50, 100, 200, 255};

    /**
     * 震动一次的方法
     *
     * @param vibratorAgent
     */
    public static void startVibrate(VibratorAgent vibratorAgent, AbilitySlice slice) {
        // 查询硬件设备上的振动器列表
        List<Integer> vibratorList = vibratorAgent.getVibratorIdList();
        if (vibratorList.isEmpty()) {
            return;
        }
        int vibratorId = vibratorList.get(0);
        boolean vibrateEffectResult = vibratorAgent.startOnce(vibratorId,
                VibrationPattern.VIBRATOR_TYPE_CAMERA_CLICK);
        if (vibrateEffectResult) {
            new ToastDialog(slice).setText("震动成功！").show();
        } else {
            new ToastDialog(slice).setText("未震动！").show();
        }
    }

    public static void startTimeVibrate(VibratorAgent vibratorAgent, AbilitySlice slice) {
        // 查询硬件设备上的振动器列表
        List<Integer> vibratorList = vibratorAgent.getVibratorIdList();
        if (vibratorList.isEmpty()) {
            return;
        }
        int vibratorId = vibratorList.get(0);
        // 创建指定振动时长的一次性振动
        int vibratorTiming = 1000;
        boolean vibrateResult = vibratorAgent.startOnce(vibratorId, vibratorTiming);
        if (vibrateResult) {
            new ToastDialog(slice).setText("震动成功！").show();
        } else {
            new ToastDialog(slice).setText("未震动！").show();
        }
    }
}
